package logic

import (
	"context"
	"shop/shoprpc/shoprpc"

	"shop/api/internal/svc"
	"shop/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CardAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCardAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CardAddLogic {
	return &CardAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CardAddLogic) CardAdd(req *types.CardAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	data, err := l.svcCtx.ShopRpc.CardAdd(l.ctx, &shoprpc.CardAddRequest{
		UserId:    req.UserId,
		ProductId: req.ProductId,
		Number:    req.Number,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    nil,
			Data:    500,
		}, nil
	}
	return &types.Response{
		Message: "购物车添加成功",
		Code:    data,
		Data:    200,
	}, nil
}
